package com.fr.data.console;

import com.fr.base.FRContext;
import com.fr.base.file.DatasourceManager;
import com.fr.data.AbstractTableData;
import com.fr.data.TableDataException;
import com.fr.data.impl.Connection;
import com.fr.data.impl.JDBCDatabaseConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class JDBCDataBaseConnectionTableData extends AbstractTableData
{
  private String[] columnNames = { "Check", "Name", "DataBaseType", "Driver", "URL", "User", "Password", "originalCharsetName", "newCharsetName", "delete", "modify" };
  private List dataList = new ArrayList();

  public JDBCDataBaseConnectionTableData()
  {
    transform();
  }

  public int getColumnCount()
    throws TableDataException
  {
    return this.columnNames.length;
  }

  public String getColumnName(int paramInt)
    throws TableDataException
  {
    return this.columnNames[paramInt];
  }

  public int getRowCount()
    throws TableDataException
  {
    return this.dataList.size();
  }

  public Object getValueAt(int paramInt1, int paramInt2)
  {
    if ((paramInt1 >= this.dataList.size()) || (paramInt2 >= this.columnNames.length))
      return null;
    return ((Object[])this.dataList.get(paramInt1))[paramInt2];
  }

  public void transform()
  {
    DatasourceManager localDatasourceManager = FRContext.getDatasourceManager();
    Iterator localIterator = localDatasourceManager.getConnectionNameIterator();
    while (true)
    {
      String str1;
      Connection localConnection;
      do
      {
        if (!(localIterator.hasNext()))
          return;
        str1 = (String)localIterator.next();
        localConnection = localDatasourceManager.getConnection(str1);
      }
      while (!(localConnection instanceof JDBCDatabaseConnection));
      JDBCDatabaseConnection localJDBCDatabaseConnection = (JDBCDatabaseConnection)localConnection;
      Object[] arrayOfObject = new Object[this.columnNames.length];
      arrayOfObject[0] = new Boolean(true);
      arrayOfObject[1] = str1;
      String str2 = localJDBCDatabaseConnection.getDriver();
      String str3 = localJDBCDatabaseConnection.getURL();
      if (str2.equals("sun.jdbc.odbc.JdbcOdbcDriver"))
        if (str3.indexOf(".mdb") > 0)
          arrayOfObject[2] = new Integer(6);
        else
          arrayOfObject[2] = new Integer(10);
      else if (str2.equals("org.apache.derby.jdbc.ClientDriver"))
        arrayOfObject[2] = new Integer(7);
      else if (str2.equals("oracle.jdbc.driver.OracleDriver"))
        arrayOfObject[2] = new Integer(1);
      else if (str2.equals("com.ibm.db2.jcc.DB2Driver"))
        arrayOfObject[2] = new Integer(2);
      else if (str2.equals("com.microsoft.sqlserver.jdbc.SQLServerDriver"))
        arrayOfObject[2] = new Integer(9);
      else if (str2.equals("org.gjt.mm.mysql.Driver"))
        arrayOfObject[2] = new Integer(4);
      else if (str2.equals("com.mysql.jdbc.Driver"))
        arrayOfObject[2] = new Integer(4);
      else if (str2.equals("org.hsqldb.jdbcDriver"))
        arrayOfObject[2] = new Integer(10);
      else if (str2.equals("com.sybase.jdbc2.jdbc.SybDriver"))
        arrayOfObject[2] = new Integer(5);
      else if (str2.equals("com.inet.tds.TdsDriver"))
        arrayOfObject[2] = new Integer(10);
      else if (str2.equals("org.postgresql.Driver"))
        arrayOfObject[2] = new Integer(8);
      else if (str2.equals("COM.cloudscape.JDBCDriver"))
        arrayOfObject[2] = new Integer(10);
      else if (str2.equals("com.internetcds.jdbc.tds.Driver"))
        arrayOfObject[2] = new Integer(10);
      else if (str2.equals("com.microsoft.jdbc.sqlserver.SQLServerDriver"))
        arrayOfObject[2] = new Integer(3);
      else
        arrayOfObject[2] = new Integer(0);
      arrayOfObject[3] = str2;
      arrayOfObject[4] = str3;
      arrayOfObject[5] = localJDBCDatabaseConnection.getUser();
      arrayOfObject[6] = localJDBCDatabaseConnection.getPassword();
      arrayOfObject[7] = localJDBCDatabaseConnection.getOriginalCharsetName();
      arrayOfObject[8] = localJDBCDatabaseConnection.getNewCharsetName();
      arrayOfObject[9] = null;
      arrayOfObject[10] = null;
      this.dataList.add(arrayOfObject);
    }
  }
}